#import "RCChoiceTableView.h"

@implementation RCChoiceTableView
- (void)awakeFromNib {
	items = [NSMutableArray new];
	[self setDelegate:self];
	[self setDataSource:self];
	[self reloadData];
}

- (void)dealloc {
	[items release];
	[super dealloc];
}
- (NSMutableArray *)items {
	return items;
}

- (id)selectedRowItemforColumnIdentifier:(NSString *)anIdentifier {
	if ([self selectedRow] != -1)
		return [[items objectAtIndex:[self selectedRow]] objectForKey:anIdentifier];
}

- (void)setItems:(NSMutableArray *)anArray {

	if (items == anArray)
                return;
        [items release];
	items = anArray;
        [items retain];
	[self reloadData];
}

- (void)addRow:(NSDictionary *)item {
	[items insertObject:item atIndex:[items count]];
	[self reloadData];
}

- (void)removeRow:(unsigned)row {
	[items removeObjectAtIndex:row];
	[self reloadData];
}

- (int)numberOfRowsInTableView:(NSTableView *)tableView {
	return [items count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row {
	if (row != -1)
		return [[items objectAtIndex:row] objectForKey:[tableColumn identifier]];
}

@end
